@extends('webadmin.index')
@section('title','用户列表')
@section('myStyle')
<style type="text/css">
	.pagination {
		float:right;
		list-style: none;

	}
	.pagination li{
		float:left;
		margin:10px 8px 10px 0px;
	}
</style>
@endsection
@section('content')
<div class="mws-panel grid_8">
	<div class="mws-panel-header">
    	<span><i class="icon-table"></i>用户列表</span>
    </div>
    <div class="mws-panel-body no-padding">
        <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
        <form action="/admin/user" method="get">
	        <div id="DataTables_Table_1_length" class="dataTables_length"><label>显示<select size="1" name="num" aria-controls="DataTables_Table_1">
	        <option value="10" @if(!empty($data['num']) && $data['num'] == 10) selected @endif>10</option>
	        <option value="25"@if(!empty($data['num']) && $data['num'] == 25) selected @endif>25</option>
	        <option value="50" @if(!empty($data['num']) && $data['num'] == 50) selected @endif>50</option>
	        <option value="100"@if(!empty($data['num']) && $data['num'] == 100) selected @endif>100</option>
	        </select> 条</label>
	        </div>
			<div class="dataTables_filter" id="DataTables_Table_1_filter"><label>关键字: <input type="text" aria-controls="DataTables_Table_1" name="keywords" value="{{$data['keywords'] or ''}}">
			<button class="btn btn-primary">搜索</button>
	        	</label>
	        </div>
	    </form>
        <table class="mws-datatable-fn mws-table dataTable" id="DataTables_Table_1" aria-describedby="DataTables_Table_1_info">
            <thead>
                <tr role="row"><th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_1" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Rendering engine: activate to sort column descending" style="width: 157px;">ID</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_1" rowspan="1" colspan="1" aria-label="Browser: activate to sort column ascending" style="width: 209px;">用户名</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_1" rowspan="1" colspan="1" aria-label="Platform(s): activate to sort column ascending" style="width: 191px;">邮箱</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_1" rowspan="1" colspan="1" aria-label="Engine version: activate to sort column ascending" style="width: 137px;">状态</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_1" rowspan="1" colspan="1" aria-label="CSS grade: activate to sort column ascending" style="width: 101px;">操作</th></tr>
            </thead>
        <tbody role="alert" aria-live="polite"   aria-relevant="all">
				@foreach($user as $k=>$v)
        		<tr class="@if($v['id'] % 2) odd @else even @endif">
                    <td class="sorting_1">{{$v['id']}}</td>
                    <td class=" ">{{$v['name']}}</td>
                    <td class=" ">{{$v['email']}}</td>
                    <td class=" ">@if($v['status']==0)<button class="btn btn-success status" name="{{$v['status']}}"><i class="icon-cd"></i></button>@else<button class="btn btn-danger status" name="{{$v['status']}}"><i class="icon-ban-circle"></i></button>@endif</td>                  
                    <td class=" ">
                    	<form action="/admin/user/{{$v['id']}}" method="POST">
                    		{{csrf_field()}}
                    		<input type="hidden" name="_method" value="DELETE">
                    		<button class="btn btn-warning"><i class="icon-trash"></i></button>
                    	</form>
                    </td>
                </tr>
                @endforeach
         </tbody>
     </table>
                <div class="dataTables_info" id="DataTables_Table_1_info">{{count($user)}}
                </div>
                <div>
				{!! $user->appends(['data'=>$data])->render() !!}    
				</div>
    </div>
</div>
@endsection
@section('myJs')
<script type="text/javascript">
	var buttons = $('.status');
	buttons.click(function(){
		var status = $(this).attr('name');
		var id = $(this).parents('tr').find('.sorting_1').html();
		var button = $(this);
		$.get('/admin/user/'+id+'/edit',{status:status},function(data){
			console.log(data);
			if(data == 0){
				button.attr('name','0');
				button.find('i').attr('class','icon-cd');
				button.attr('class','btn btn-success status');
			}else{
				button.attr('class','btn btn-danger status');
				button.attr('name','1');
				button.find('i').attr('class','icon-ban-circle');
			}
		});
	});
</script>
@endsection